home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / rj.arc / RJ.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-06-05  |  3.0 KB  |  110 lines

  1. /****************************************************************/
  2. /*                                */
  3. /* rj.c        06/19/86                    */
  4. /*                                */
  5. /* this program sends a command line to another network        */
  6. /* station for remote execution.  The other network station    */
  7. /* must be running rjexec.  A message will be returned and    */
  8. /* printed on the bottome line when the remote job is complete.    */
  9. /*                                */
  10. /* rev 1.1  07/11/86  recompile to use revised semopen call    */
  11. /*                                */
  12. /****************************************************************/
  13.  
  14. #include <string.h>
  15. #include "novell.h"
  16.  
  17. main(argc, argv)
  18. int argc;
  19. char *argv[];
  20. {
  21.     int user_no;
  22.     int result, value, users;
  23.     unsigned long handle;
  24.     char station[64];
  25.     int i;
  26.     char cmnd_line[128], message[128];
  27.     long ltime, target_time;
  28.     char c;
  29.  
  30.     printf("Remote job submission program  --  Ver. 1.1\n");
  31.     printf("For Novell Netware\n");
  32.     printf("Copyright (c) 1986  --  Ken Hales\n\n");
  33.  
  34.     /********************************************************/
  35.     /* make sure there is a command to send            */
  36.     /********************************************************/
  37.  
  38.     if (argc < 2) {
  39.         printf("Usage: rj <command line>\n");
  40.         exit(1);
  41.     }
  42.  
  43.     /********************************************************/
  44.     /* find out who is running rjexec            */
  45.     /********************************************************/
  46.  
  47.     result = semopen("rj", 0, &handle, &users);
  48.  
  49.     if (result != 0) {
  50.         printf("Problem opening semaphore: %d\n", result);
  51.         printf("Program aborted\n");
  52.         exit(1);
  53.     }
  54.  
  55.     if (users < 2) {
  56.         printf("No workstation is currently running rjexec.\n");
  57.         printf("Program aborted\n");
  58.         semclose(handle);
  59.         exit(1);
  60.     }
  61.  
  62.     result = semexam(handle, &value, &users);
  63.  
  64.     if (result != 0) {
  65.         printf("Problem examining semaphore: %d\n", result);
  66.         printf("Program aborted\n");
  67.         semclose(handle);
  68.         exit(1);
  69.     }
  70.  
  71.     /********************************************************/
  72.     /* open a message pipe to the remote job workstation    */
  73.     /********************************************************/
  74.  
  75.     station[0] = value;
  76.     pipopen(1, station);
  77.  
  78.     /********************************************************/
  79.     /* send command to the remote job workstation by    */
  80.     /* writing to its message pipe.                */
  81.     /********************************************************/
  82.  
  83.     strcpy(message, argv[1]);
  84.     for (i=2; i<argc; i++) {
  85.         strcat(message, " ");
  86.         strcat(message, argv[i]);
  87.     }
  88.  
  89.     station[0] = value;
  90.     pipwrite(1, station, message);
  91.  
  92.     if (station[0] != 0) {
  93.         printf("Not successful.\n");
  94.         printf("Remote workstation queue is probably full.\n");
  95.         result = 1;
  96.     } else {
  97.         printf("Job has been successfully sent to remote workstation.\n");
  98.         result = 0;
  99.     }
  100.  
  101.     /********************************************************/
  102.     /* done - close semaphore and pipe, then exit        */
  103.     /********************************************************/
  104.  
  105.     station[0] = value;
  106.     pipclose(1, station);
  107.     semclose(handle);
  108.     exit(result);
  109. }
  110.